package com.example.companybusiness.operationt.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.companybusiness.R;
import com.example.companybusiness.operationt.bean.HotStoriesBean;

import java.util.List;

public class HotStoriesAdapter extends RecyclerView.Adapter<HotStoriesAdapter.MyViewHolder>
{
    private List<HotStoriesBean> data;

    private Context context;

    public HotStoriesAdapter(Context context) {
        this.context = context;
    }

    public void setData(List<HotStoriesBean> data) {
        this.data = data;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
    {
        return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.item_list_hotstories,null));
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position)
    {
        holder.imageView.setImageResource(data.get(position).getReported());
        holder.textViewc.setText(data.get(position).getContent());
        holder.textViewt.setText(data.get(position).getTime());
    }

    @Override
    public int getItemCount()
    {
        return data != null ? data.size():0;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder
    {

        ImageView imageView;
        TextView textViewc;
        TextView textViewt;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.item_list_hotstories_img_reported);
            textViewc = itemView.findViewById(R.id.item_list_hotstories_tv_content);
            textViewt = itemView.findViewById(R.id.item_list_hotstories_tv_time);
        }
    }
}

